package hk.ust.comp3111.ustnutrition.data.json;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ApiResponseRank extends ApiResponseBase {
	
	String[] names;
	double[] scores;
	Integer rank;
	
	public void load(JSONObject obj) throws JSONException {
		super.load(obj);
		JSONArray ary = obj.getJSONArray("data");
		names = new String[ary.length()];
		scores = new double[ary.length()];
		
		for(int i = 0; i < names.length; i++) {
			names[i] = ary.getJSONObject(i).getString("name");
			scores[i] = ary.getJSONObject(i).getDouble("score");
		}
		
		if(obj.has("rank"))
			rank = obj.getInt("rank");
	}
	
	public String getName(int i) {
		return names[i];
	}
	
	public double getScore(int i) {
		return scores[i];
	}
	
	public int getLength() {
		return names.length;
	}
	
	public Integer getRank() {
		return rank;
	}
}



